<template>
	<view>
		<view class="bg"></view>
		<list :schoolList="schoolList" :attrList="attrList"></list>
	</view>
</template>

<script lang="ts" setup>
	import { provide, ref } from 'vue';
	import { onLoad } from '@dcloudio/uni-app';
	import bus from '@/utils/bus.js';
	import list from '@/components/tabbar/index/list/list.vue';
	import {
		getSchoolListService,
		getSchoolAttrListService
	} from '@/api/index.js';
	
	const attr = ref('');
	const schoolList = ref([]);
	const attrList = ref([]);
	
	
	//获取学校列表
	const getSchoolList = async (str) => {
		const res = await getSchoolListService(str);
		schoolList.value = res.data;
		// console.log('获取学校列表成功',JSON.parse(JSON.stringify(schoolList.value)));
	}
	//获取学校属性列表
	const getSchoolAttrList = async () => {
		const res = await getSchoolAttrListService();
		attrList.value = res.data
		// console.log('获取学校属性列表成功',JSON.parse(JSON.stringify(attrList.value)));
	}
	
	onLoad(async (options) => {
		console.log('获取的参数',options);
		await getSchoolAttrList();
		if(options.attrStr){
			attr.value = options.attrStr;
			let ary = JSON.parse(JSON.stringify(attrList.value));
			let obj = {
				ary: ary,
				inx: options.attrStr
			}
			bus.emit('getAttrName',obj);
		}
		getSchoolList(JSON.parse(JSON.stringify(attr.value)));
	})
	
	bus.on('getNewAttr',(str) => {
		attr.value = str;
		// console.log('事件bus下的attr',JSON.parse(JSON.stringify(attr.value)));
		getSchoolList(JSON.parse(JSON.stringify(attr.value)));
	});
</script>

<style lang="scss" scoped>
	.bg{
		background-color: $uni-bg-color-grey;
		width: 100%;height: 100%;
		position: absolute;
		z-index: -1;
	}
</style>